<template>
    <div class="hcj_message_box" :class="{
        'hcj_message_success': type == 'success',
        'hcj_message_error': type == 'error',
        'hcj_message_left': place == 'left',
        'hcj_message_right': place == 'right'
    }">
        {{ message }}
    </div>
</template>

<script>
export default {
    props: {
        message: {
            type: String,
            default: '这是一条消息提示！'
        },
        type: {
            type: String,
            default: 'default'
        },
        place: {
            type: String,
            default: 'default'
        }
    },
    data() {
        return {
            timer: 1500,
        }
    },
    mounted() {
        this.showMine()
    },
    methods: {
        showMine() {
            document.body.appendChild(this.$el)
            let message_box = document.getElementsByClassName('hcj_message_box')
            let timer = this.timer
            console.log(message_box)
            setTimeout((timer) => {
                message_box[0].style.opacity = 0
                setTimeout(()=>{
                    document.body.removeChild(message_box[0])
                },100)
            }, timer);
        }
    }
}
</script>

<style scoped>
.hcj_message_box
{
    position: absolute;
    top: 30px;
    left: 50%;
    transform: translate(-50%, 0%);
    text-align: center;
    /* width: 200px; */
    height: 50px;
    padding: 0 20px;
    line-height: 50px;
    border-radius: 10px;
    background-color: white;
    /* color: #43CD80; */
    color: #2c3e50;
    font-weight: 900;
    box-shadow: 1px 1px 5px #2c3e50;
    animation: showMessage 0.5s ease-in-out;
    transition: all 0.4s;
}
.hcj_message_success {
    left: 50%;
    color: #43CD80;
    box-shadow: 1px 1px 5px #43CD80;
}
.hcj_message_error {
    left: 50%;
    color: orangered;
    box-shadow: 1px 1px 5px orangered;
}
.hcj_message_left {
    left: 10%;
}
.hcj_message_right {
    left: auto;
    right: 5%;
}
@keyframes showMessage
{
    0%
    {
        opacity: 0.3;
        top: 100px;
    }

    100%
    {
        opacity: 1;
        top: 30px;
    }
}
</style>